<?php namespace module\web;

use module\HdSite;

class Site extends HdSite {


//    前台页面
    public function AdminIndex(){
        $data = Db::table( 'plugin_web_article' )->paginate( 10 );
        View::with( 'data', $data );
        $this->display( 'articles' );
    }

//    发表文章
    public function AdminarticlePost(){
        if(IS_POST){
            Validate::make( [
                [ 'title', 'required', '标题不能为空' ],
                [ 'content', 'required', '内容不能为空' ]
            ] );
            $_POST['create_at'] = time();
            Db::table( 'plugin_web_article' )->insert( Request::post() );
            message( '保存成功', site_url( 'site/index' ), 'success' );
        }
        $cat = Db::table( 'plugin_web_catgory' )->get();
        View::with( 'cat', $cat );
        $this->display( 'article_post' );
    }

//    栏目列表
    public function AdmincatLists(){
        $data = Db::table( 'plugin_web_catgory' )->get();
        View::with( 'data', $data );
        $this->display( 'cat_lists' );
    }

//    修改栏目
    public function admincatPost(){
        if(IS_POST){
            Validate::make( [
                [ 'name', 'required', '标题不能为空' ],
            ] );
            Db::table( 'plugin_web_catgory' )->insert( Request::post() );
            message( '保存成功', site_url( 'site/catLists' ), 'success' );
        }
        $this->display('cat_post');
    }

//    首页
    public function webHome(){
        $data = Db::table( 'plugin_web_article' )->get();
        View::with( 'data', $data );
        $this->display( 'theme/default/index.html' );
    }

//    首页
    public function webShow(){
        $id =Request::get('id');
        $field = Db::table( 'plugin_web_article' )->find($id);
        View::with( 'field', $field );
        $this->display( 'theme/default/article.html' );
    }

}